package com.team5101.service.impl;


import com.team5101.dao.IHotFsDao;
import com.team5101.entity.NowFilm;
import com.team5101.service.IHotFsService;
import com.team5101.utils.FenYeUtile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class IHotFsServiceImpl implements IHotFsService {
    @Autowired
    private IHotFsDao iHotFsDao;
     //未查看可否有用
    public int addfilmfromnextfilm(NowFilm nowFilm) {
        return 0;
    }

    public List<NowFilm> selectMovies() {    //查询所有的电影信息
        return iHotFsDao.selectMovies();
    }

    public NowFilm updataMovies(Integer fnId) { //查询要修改的电影信息
        return iHotFsDao.updataMovie(fnId);
    }

    public Integer updata(NowFilm nowFilm) {    //修改电影信息
        return iHotFsDao.updata(nowFilm);
    }

    public Integer dele(Integer fnId) {         //删除相应的电影信息
        return iHotFsDao.dele(fnId);
    }

    public FenYeUtile selectOnePage(Integer currentPage) {
        //分页，传入一个用户想看的页面，前端传来的
            Integer allCount = iHotFsDao.selectCount();//查询电影表，返回所有的条数 1
            FenYeUtile fy = new FenYeUtile();
            Integer pages = fy.getPages();  //总页数
            Integer pageSize = fy.getPageSize(); //每页展示的条数，为2,
            pages = allCount/pageSize;   //总条数/每页条数=总页数                  2
            Integer start=(currentPage-1)*pageSize;//算出从几个开始
            if (allCount%pageSize==0){   //如果整除，说明pages就是真实的总页数     3
                pages=pages; //是真实的总页数
            }else{   //不能够整除
                pages++; //就说明还有余数独成一页
            }
            List<NowFilm> nowFilms = iHotFsDao.selectFYfilm(start, pageSize); //查询出用户想看页的信息
            fy.setAllCount(allCount);
            fy.setCurrentPage(currentPage);
            fy.setOnMovies(nowFilms);
            fy.setPages(pages);
            fy.setPageSize(pageSize);
            return fy;
        }

        public List<NowFilm> vaguesele(String fnName) {     //模糊查询出来的电影信息
//             System.out.println(fnName);
            List<NowFilm> list = iHotFsDao.vaguesele(fnName);
//             System.out.println(list);
            return iHotFsDao.vaguesele(fnName);
        }

        public Integer insertMovie(NowFilm nowFilm) {
            Integer integer = iHotFsDao.insertMovie(nowFilm);
            return integer;
        }

        public NowFilm queryFilm(Integer fn_id) {
            return iHotFsDao.queryFilm(fn_id);
        }
}
